****************************************************************************
* File-Nale: 		datapreparationR.do
* Date:		 04/10/2020
* Author: 		Fred Batista
* Purpose: 		Data preparation for ideal point estimation in R (IRT paper)
* Data used: 		AmericasBarometer 2010 
* Data Output:	lapop10irt.dta	*/
****************************************************************************

****Open AB 2010 dataset

**** knowledge items

generate uspres = gi1

generate province = gi3

generate timeterm = gi4

recode uspres province timeterm (2=0) (1=1) (.=0)

label variable province "Knows number of provinces"

label variable uspres "Knows US president"

label variable timeterm "Knows duration of presidential term"

gen polknow=timeterm + province + uspres

label variable polknow "Additive Scale of Political Knowledge"

gen polknow_0100 = polknow*(100/3)

label variable polknow_0100 "Additive Scale of Political Knowledge from 0 to 100"

* new country variable

gen country = pais

recode country (21=18) (22=19) (23=20) (24=21) (25=22) (26=23) (27=24)

label variable country "Country"

gen country2=country

label variable country2 "Country variable without labels"

label define country2l 1 "Mexico" 2 "Guatemala" 3 "El Salvador" 4 "Honduras" 5 "Nicaragua" 6 "Costa Rica" 7 "Panama" 8 "Colombia" 9 "Ecuador" 10 "Bolivia" 11 "Peru" 12 "Paraguay" 13 "Chile" 14 "Uruguay" 15 "Brazil" 16 "Venezuela" 17 "Argentina" 18 "Domincan Republic" 19 "Haiti" 20 "Jamaica" 21 "Guyana" 22 "Trinidad & Tobago" 23 "Belize" 24 "Suriname" 

label values country2 country2l


************** First level independent variables
 
gen wealth = quintall

label variable wealth "Wealth"

gen income = q10

label variable income "Income"

gen interest = 4 - pol1

gen assets = r1 + r3 + r4 + r4a + r5 + r6 + r7 + r8 + r12 + r14 + r15 + r16 + r18

label variable assets "Number of household assets"

gen mediaassets = r1 + r4 + r4a + r15 + r18

label variable mediaassets "Assets associated to media consumption"

gen otherassets =  r3 +  r5 + r6 + r7 + r8 + r12 + r14 + r16

label variable otherassets "Assets other than mediassets"

label variable interest "Political interest"

gen exposure = 5 -gi0

label variable exposure "Media exposure"

recode ocup4a (1/4 = 1) (6=1) (5=0) (7=0), gen (employed)

label variable employed "Employed"

gen man = 2 - q1

label variable man "Man"

gen age2 = q2s

label variable age2 "Age"

gen schooling = ed

label variable schooling "Education"

gen efficacy = eff2 - 1

label variable efficacy "Internal efficacy"

gen voted = vb2r/100

label variable voted "Voted in last national elections"


**** dropping non-used variables

keep idnum weight1500 estratopri upm prov municipio cluster uspres timeterm province polknow wealth schooling urban man age2 employed interest exposure efficacy country country2 income assets mediaassets otherassets voted


** creating standardized knowledge additive scale

* knowledge items by country, missing for the rest

generate uspresc1 = uspres if country == 1

replace uspresc1 = . if country != 1

generate provincec1 = province if country == 1

replace provincec1 = . if country != 1

generate timetermc1 = timeterm if country == 1

replace timetermc1 = . if country != 1

generate uspresc2 = uspres if country == 2

replace uspresc2 = . if country != 2

generate provincec2 = province if country == 2

replace provincec2 = . if country != 2

generate timetermc2 = timeterm if country == 2

replace timetermc2 = . if country != 2

generate uspresc3 = uspres if country == 3

replace uspresc3 = . if country != 3

generate provincec3 = province if country == 3

replace provincec3 = . if country != 3

generate timetermc3 = timeterm if country == 3

replace timetermc3 = . if country != 3

generate uspresc4 = uspres if country == 4

replace uspresc4 = . if country != 4

generate provincec4 = province if country == 4

replace provincec4 = . if country != 4

generate timetermc4 = timeterm if country == 4

replace timetermc4 = . if country != 4

generate uspresc5 = uspres if country == 5

replace uspresc5 = . if country != 5

generate provincec5 = province if country == 5

replace provincec5 = . if country != 5

generate timetermc5 = timeterm if country == 5

replace timetermc5 = . if country != 5

generate uspresc6 = uspres if country == 6

replace uspresc6 = . if country != 6

generate provincec6 = province if country == 6

replace provincec6 = . if country != 6

generate timetermc6 = timeterm if country == 6

replace timetermc6 = . if country != 6

generate uspresc7 = uspres if country == 7

replace uspresc7 = . if country != 7

generate provincec7 = province if country == 7

replace provincec7 = . if country != 7

generate timetermc7 = timeterm if country == 7

replace timetermc7 = . if country != 7

generate uspresc8 = uspres if country == 8

replace uspresc8 = . if country != 8

generate provincec8 = province if country == 8

replace provincec8 = . if country != 8

generate timetermc8 = timeterm if country == 8

replace timetermc8 = . if country != 8

generate uspresc9 = uspres if country == 9

replace uspresc9 = . if country != 9

generate provincec9 = province if country == 9

replace provincec9 = . if country != 9

generate timetermc9 = timeterm if country == 9

replace timetermc9 = . if country != 9

generate uspresc10 = uspres if country == 10

replace uspresc10 = . if country != 10

generate provincec10 = province if country == 10

replace provincec10 = . if country != 10

generate timetermc10 = timeterm if country == 10

replace timetermc10 = . if country != 10

generate uspresc11 = uspres if country == 11

replace uspresc11 = . if country != 11

generate provincec11 = province if country == 11

replace provincec11 = . if country != 11

generate timetermc11 = timeterm if country == 11

replace timetermc11 = . if country != 11

generate uspresc12 = uspres if country == 12

replace uspresc12 = . if country != 12

generate provincec12 = province if country == 12

replace provincec12 = . if country != 12

generate timetermc12 = timeterm if country == 12

replace timetermc12 = . if country != 12

generate uspresc13 = uspres if country == 13

replace uspresc13 = . if country != 13

generate provincec13 = province if country == 13

replace provincec13 = . if country != 13

generate timetermc13 = timeterm if country == 13

replace timetermc13 = . if country != 13

generate uspresc14 = uspres if country == 14

replace uspresc14 = . if country != 14

generate provincec14 = province if country == 14

replace provincec14 = . if country != 14

generate timetermc14 = timeterm if country == 14

replace timetermc14 = . if country != 14

generate uspresc15 = uspres if country == 15

replace uspresc15 = . if country != 15

generate provincec15 = province if country == 15

replace provincec15 = . if country != 15

generate timetermc15 = timeterm if country == 15

replace timetermc15 = . if country != 15

generate uspresc16 = uspres if country == 16

replace uspresc16 = . if country != 16

generate provincec16 = province if country == 16

replace provincec16 = . if country != 16

generate timetermc16 = timeterm if country == 16

replace timetermc16 = . if country != 16

generate uspresc17 = uspres if country == 17

replace uspresc17 = . if country != 17

generate provincec17 = province if country == 17

replace provincec17 = . if country != 17

generate timetermc17 = timeterm if country == 17

replace timetermc17 = . if country != 17

generate uspresc18 = uspres if country == 18

replace uspresc18 = . if country != 18

generate provincec18 = province if country == 18

replace provincec18 = . if country != 18

generate timetermc18 = timeterm if country == 18

replace timetermc18 = . if country != 18

generate uspresc19 = uspres if country == 19

replace uspresc19 = . if country != 19

generate provincec19 = province if country == 19

replace provincec19 = . if country != 19

generate timetermc19 = timeterm if country == 19

replace timetermc19 = . if country != 19

generate uspresc20 = uspres if country == 20

replace uspresc20 = . if country != 20

generate provincec20 = province if country == 20

replace provincec20 = . if country != 20

generate timetermc20 = timeterm if country == 20

replace timetermc20 = . if country != 20

generate uspresc21 = uspres if country == 21

replace uspresc21 = . if country != 21

generate provincec21 = province if country == 21

replace provincec21 = . if country != 21

generate timetermc21 = timeterm if country == 21

replace timetermc21 = . if country != 21

generate uspresc22 = uspres if country == 22

replace uspresc22 = . if country != 22

generate provincec22 = province if country == 22

replace provincec22 = . if country != 22

generate timetermc22 = timeterm if country == 22

replace timetermc22 = . if country != 22

generate uspresc23 = uspres if country == 23

replace uspresc23 = . if country != 23

generate provincec23 = province if country == 23

replace provincec23 = . if country != 23

generate timetermc23 = timeterm if country == 23

replace timetermc23 = . if country != 23

generate uspresc24 = uspres if country == 24

replace uspresc24 = . if country != 24

generate provincec24 = province if country == 24

replace provincec24 = . if country != 24

generate timetermc24 = timeterm if country == 24

replace timetermc24 = . if country != 24


* generating a standardized additive scale

egen std1 = std(provincec1 + timetermc1 + uspresc1)
egen std2 = std(provincec2 + timetermc2 + uspresc2)
egen std3 = std(provincec3 + timetermc3 + uspresc3)
egen std4 = std(provincec4 + timetermc4 + uspresc4)
egen std5 = std(provincec5 + timetermc5 + uspresc5)
egen std6 = std(provincec6 + timetermc6 + uspresc6)
egen std7 = std(provincec7 + timetermc7 + uspresc7)
egen std8 = std(provincec8 + timetermc8 + uspresc8)
egen std9 = std(provincec9 + timetermc9 + uspresc9)
egen std10 = std(provincec10 + timetermc10 + uspresc10)
egen std11 = std(provincec11 + timetermc11 + uspresc11)
egen std12 = std(provincec12 + timetermc12 + uspresc12)
egen std13= std(provincec13 + timetermc13 + uspresc13)
egen std14 = std(provincec14 + timetermc14 + uspresc14)
egen std15 = std(provincec15 + timetermc15 + uspresc15)
egen std16 = std(provincec16 + timetermc16 + uspresc16)
egen std17 = std(provincec17 + timetermc17 + uspresc17)
egen std18 = std(provincec18 + timetermc18 + uspresc18)
egen std19 = std(provincec19 + timetermc19 + uspresc19)
egen std20 = std(provincec20 + timetermc20 + uspresc20)
egen std21 = std(provincec21 + timetermc21 + uspresc21)
egen std22 = std(provincec22 + timetermc22 + uspresc22)
egen std23 = std(provincec23 + timetermc23 + uspresc23)
egen std24 = std(provincec24 + timetermc24 + uspresc24)

gen stdknow =.
replace stdknow= std1 if country==1
replace stdknow= std2 if country==2
replace stdknow= std3 if country==3
replace stdknow= std4 if country==4
replace stdknow= std5 if country==5
replace stdknow= std6 if country==6
replace stdknow= std7 if country==7
replace stdknow= std8 if country==8
replace stdknow= std9 if country==9
replace stdknow= std10 if country==10
replace stdknow= std11 if country==11
replace stdknow= std12 if country==12
replace stdknow= std13 if country==13
replace stdknow= std14 if country==14
replace stdknow= std15 if country==15
replace stdknow= std16 if country==16
replace stdknow= std17 if country==17
replace stdknow= std18 if country==18
replace stdknow= std19 if country==19
replace stdknow= std20 if country==20
replace stdknow= std21 if country==21
replace stdknow= std22 if country==22
replace stdknow= std23 if country==23
replace stdknow= std24 if country==24

summarize stdknow

label variable stdknow "Additive Political Knowledge Standardized By Country"

gen stdknow_0100 = (stdknow + 3.815124 )*100/(3.815124 + 1.700503)

label variable stdknow_0100 "Additive Political Knowledge Standardized By Country 0-100"


* creating factor scores for each country

factor provincec1 timetermc1 uspresc1, ml factor(1)
predict facknow1

factor provincec2 timetermc2 uspresc2, ml factor(1)
predict facknow2

factor provincec3 timetermc3 uspresc3, ml factor(1)
predict facknow3

factor provincec4 timetermc4 uspresc4, ml factor(1)
predict facknow4

factor provincec5 timetermc5 uspresc5, ml factor(1)
predict facknow5

factor provincec6 timetermc6 uspresc6, ml factor(1)
predict facknow6

factor provincec7 timetermc7 uspresc7, ml factor(1)
predict facknow7

factor provincec8 timetermc8 uspresc8, ml factor(1)
predict facknow8

factor provincec9 timetermc9 uspresc9, ml factor(1)
predict facknow9

factor provincec10 timetermc10 uspresc10, ml factor(1)
predict facknow10

factor provincec11 timetermc11 uspresc11, ml factor(1)
predict facknow11

factor provincec12 timetermc12 uspresc12, ml factor(1)
predict facknow12

factor provincec13 timetermc13 uspresc13, ml factor(1)
predict facknow13

factor provincec14 timetermc14 uspresc14, ml factor(1)
predict facknow14

factor provincec15 timetermc15 uspresc15, ml factor(1)
predict facknow15

factor provincec16 timetermc16 uspresc16, ml factor(1)
predict facknow16

factor provincec17 timetermc17 uspresc17, ml factor(1)
predict facknow17

factor provincec18 timetermc18 uspresc18, ml factor(1)
predict facknow18

factor provincec19 timetermc19 uspresc19, ml factor(1)
predict facknow19

factor provincec20 timetermc20 uspresc20, ml factor(1)
predict facknow20

factor provincec21 timetermc21 uspresc21, ml factor(1)
predict facknow21

factor provincec22 timetermc22 uspresc22, ml factor(1)
predict facknow22

factor provincec23 timetermc23 uspresc23, ml factor(1)
predict facknow23

factor provincec24 timetermc24 uspresc24, ml factor(1)
predict facknow24

gen facknow =.
replace facknow= facknow1 if country==1
replace facknow= facknow2 if country==2
replace facknow= facknow3 if country==3
replace facknow= facknow4 if country==4
replace facknow= facknow5 if country==5
replace facknow= facknow6 if country==6
replace facknow= facknow7 if country==7
replace facknow= facknow8 if country==8
replace facknow= facknow9 if country==9
replace facknow= facknow10 if country==10
replace facknow= facknow11 if country==11
replace facknow= facknow12 if country==12
replace facknow= facknow13 if country==13
replace facknow= facknow14 if country==14
replace facknow= facknow15 if country==15
replace facknow= facknow16 if country==16
replace facknow= facknow17 if country==17
replace facknow= facknow18 if country==18
replace facknow= facknow19 if country==19
replace facknow= facknow20 if country==20
replace facknow= facknow21 if country==21
replace facknow= facknow22 if country==22
replace facknow= facknow23 if country==23
replace facknow= facknow24 if country==24

summarize facknow

gen facknow_0100= 100*(facknow - r(min))/(r(max) - r(min)) 

label variable facknow "Factor Analysis Scale By Country"

label variable facknow_0100 "Factor Analysis Scale By Country 0-100"


* creating one big factor

factor province timeterm uspres, ml factor(1)

predict bigfacknow

summarize bigfacknow

gen bigfacknow_0100= 100*(bigfacknow - r(min))/(r(max) - r(min))

label variable bigfacknow "Factor analysis scale from single model"

label variable bigfacknow_0100 "Factor Analysis Scale from single model 0-100"



* dropping unused variables

drop provincec1 provincec2 provincec3 provincec4 provincec5 provincec6 provincec7 provincec8 provincec9 provincec10 provincec11 provincec12 provincec13 provincec14 provincec15 provincec16 provincec17 provincec18 provincec19 provincec20 provincec21 provincec22 provincec23 provincec24 timetermc1 timetermc2 timetermc3 timetermc4 timetermc5 timetermc6 timetermc7 timetermc8 timetermc9 timetermc10 timetermc11 timetermc12 timetermc13 timetermc14 timetermc15 timetermc16 timetermc17 timetermc18 timetermc19 timetermc20 timetermc21 timetermc22 timetermc23 timetermc24 uspresc1 uspresc2 uspresc3 uspresc4 uspresc5 uspresc6 uspresc7 uspresc8 uspresc9 uspresc10 uspresc11 uspresc12 uspresc13 uspresc14 uspresc15 uspresc16 uspresc17 uspresc18 uspresc19 uspresc20 uspresc21 uspresc22 uspresc23 uspresc24 std1 std2 std3 std4 std5 std6 std7 std8 std9 std10 std11 std12 std13 std14 std15 std16 std17 std18 std19 std20 std21 std22 std23 std24 facknow1 facknow2 facknow3 facknow4 facknow5 facknow6 facknow7 facknow8 facknow9 facknow10 facknow11 facknow12 facknow13 facknow14 facknow15 facknow16 facknow17 facknow18 facknow19 facknow20 facknow21 facknow22 facknow23 facknow24


**** dropping US and Canada

drop if country == 40

drop if country == 41


* creating id variable

sort country

gen id = _n

label variable id "Respondent's identification after removing missing data"


*** BRIDGING CASES

*** first try: different number of bridges by country

sort country

by country: count if schooling>14 & polknow==3

by country: count if schooling==0 & polknow==0


gen xp1=0

replace xp1=2 if schooling>14 & polknow==3

replace xp1=-2 if schooling==0 & polknow==0

gen xpv1 = 1

replace xpv1 = 1000000000000 if xp1!=0

label variable xp1 "Prior on mean of bridging case knowledge level"

label variable xpv1 "Prior on precision of bridging caseknowledge level"


* indicator of bridges

gen bridges = xp1

recode bridges (-2=0) (2=1) (0=.)

label variable bridges "If respondent is a bridging case"


*** second try: limited number (5%) of positive bridges per country

* sampling 5% of cases that match the bridging criteria

sort id
generate bridge = schooling>14 & polknow==3

* country 1

generate random =.
replace random =  uniform() if country==1
sort random
generate insamplec1 = _n<= 78
drop random

* country 2

sort id
generate random =.
replace random =  uniform() if country==2
sort random
generate insamplec2 = _n<= 75
drop random

* country 3

sort id
generate random =.
replace random =  uniform() if country==3
sort random
generate insamplec3 = _n<= 77
drop random

* country 4

sort id
gen insamplec4 = bridge & country==4

* country 5

gen insamplec5 = bridge & country==5

* country 6

sort id
generate random =.
replace random =  uniform() if country==6
sort random
generate insamplec6 = _n<= 75
drop random

* country 7

sort id
generate random =.
replace random =  uniform() if country==7
sort random
generate insamplec7 = _n<= 76
drop random

* country 8

sort id
generate random =.
replace random =  uniform() if country==8
sort random
generate insamplec8 = _n<= 75
drop random

* country 9

sort id
generate random =.
replace random =  uniform() if country==9
sort random
generate insamplec9 = _n<= 150
drop random

* country 10

sort id
generate random =.
replace random =  uniform() if country==10
sort random
generate insamplec10 = _n<= 150
drop random

* country 11

sort id
generate random =.
replace random =  uniform() if country==11
sort random
generate insamplec11 = _n<= 75
drop random

* country 12

sort id
generate random =.
replace random =  uniform() if country==12
sort random
generate insamplec12 = _n<= 75
drop random

* country 13

sort id
generate random =.
replace random =  uniform() if country==13
sort random
generate insamplec13 = _n<= 98
drop random

* country 14

sort id
generate random =.
replace random =  uniform() if country==14
sort random
generate insamplec14 = _n<= 75
drop random

* country 15

sort id
gen insamplec15 = bridge & country==15

* country 16

sort id
generate random =.
replace random =  uniform() if country==16
sort random
generate insamplec16 = _n<= 75
drop random

* country 17

sort id
generate random =.
replace random =  uniform() if country==17
sort random
generate insamplec17 = _n<= 70
drop random

* country 18

sort id
generate random =.
replace random =  uniform() if country==18
sort random
generate insamplec18 = _n<= 75
drop random

* country 19

sort id
generate random =.
replace random =  uniform() if country==19
sort random
generate insamplec19 = _n<= 87
drop random

* country 20

sort id
generate random =.
replace random =  uniform() if country==20
sort random
generate insamplec20 = _n<= 75
drop random

* country 21

sort id
gen insamplec21 = bridge & country==21

* country 22

sort id
gen insamplec22 = bridge & country==22

* country 23

sort id
gen insamplec23 = bridge & country==23

* country 24

sort id
generate random =.
replace random =  uniform() if country==24
sort random
generate insamplec24 = _n<= 75
drop random

sort id


* creating a variable for all cases selected and addiog the negative bridges

gen xp2 = insamplec1 +  insamplec2 + insamplec3 + insamplec4 + insamplec5 + insamplec6 + insamplec7 + insamplec8 + insamplec9 + insamplec10 + insamplec11 + insamplec12 + insamplec13 + insamplec14 + insamplec15 + insamplec16 + insamplec17 + insamplec18 + insamplec19 + insamplec20 + insamplec21 + insamplec22 + insamplec23 + insamplec24

recode xp2 (1=2)

replace xp2 = -2 if schooling==0 & polknow==0

drop insamplec1  insamplec2 insamplec3 insamplec4 insamplec5 insamplec6 insamplec7 insamplec8 insamplec9 insamplec10 insamplec11 insamplec12 insamplec13 insamplec14 insamplec15 insamplec16 insamplec17 insamplec18 insamplec19 insamplec20 insamplec21 insamplec22 insamplec23 insamplec24

drop bridge

* setting prior precision for bridges

gen xpv2 = 1

replace xpv2 = 1000000000000 if xp2!=0

label variable xp2 "Prior on mean of bridging case knowledge level - 5% positive bridges"

label variable xpv2 "Prior on precision of bridging caseknowledge level - 5% positive bridges"


**** COUNTRY LEVEL VARIABLES

*** Freedom House Inverted

generate freehinv09=4 if country==1 
replace freehinv09=2 if country==2 
replace freehinv09=4 if country==3 
replace freehinv09=3 if country==4 
replace freehinv09=2 if country==5 
replace freehinv09=7 if country==6 
replace freehinv09=6 if country==7 
replace freehinv09=2 if country==8
replace freehinv09=3 if country==9 
replace freehinv09=3 if country==10 
replace freehinv09=4 if country==11 
replace freehinv09=3 if country==12
replace freehinv09=7 if country==13 
replace freehinv09=7 if country==14
replace freehinv09=5 if country==15
replace freehinv09=1 if country==16
replace freehinv09=5 if country==17 
replace freehinv09=5 if country==18
replace freehinv09=0 if country==19
replace freehinv09=4 if country==20
replace freehinv09=4 if country==21
replace freehinv09=5 if country==22
replace freehinv09=6 if country==23
replace freehinv09=5 if country==24
label variable freehinv09 "Freedom House 2009 Inverted"

*** Regime Duration ( From Pippa Norris's Time Series, Belize replace by mean)

generate durable=12 if country==1 
replace durable=13 if country==2 
replace durable=25 if country==3 
replace durable=27 if country==4 
replace durable=19 if country==5 
replace durable=60 if country==6 
replace durable=20 if country==7 
replace durable=51 if country==8
replace durable=9 if country==9 
replace durable=27 if country==10 
replace durable=8 if country==11 
replace durable=17 if country==12
replace durable=20 if country==13 
replace durable=24 if country==14
replace durable=24 if country==15
replace durable=41 if country==16
replace durable=26 if country==17 
replace durable=13 if country==18
replace durable=3 if country==19
replace durable=7 if country==20
replace durable=50 if country==21
replace durable=47 if country==22
replace durable=24 if country==23
replace durable=35 if country==24
label variable durable "Regime Duration"

*** Democratic Stock (Gerring)

generate stock09=-47.05 if country==1 
replace stock09=49.32 if country==2 
replace stock09=50.01 if country==3 
replace stock09=136.22 if country==4 
replace stock09=-48.88 if country==5 
replace stock09=495 if country==6 
replace stock09=72.38 if country==7 
replace stock09=286.92 if country==8
replace stock09=181.77 if country==9 
replace stock09=103.15 if country==10 
replace stock09=116.94 if country==11 
replace stock09=-97.31 if country==12
replace stock09=158.34 if country==13 
replace stock09=239.06 if country==14
replace stock09=102.74 if country==15
replace stock09=225.52 if country==16
replace stock09=60.61 if country==17 
replace stock09=64.42 if country==18
replace stock09=-161.07 if country==19
replace stock09=361.93 if country==20
replace stock09=42.83 if country==21
replace stock09=324.5 if country==22
replace stock09=. if country==23
replace stock09=77.9 if country==24
label variable stock09 "Democratic Stock in 2009"


*** Democratic Stock only after Third Wave

generate stock09_2=86.22 if country==1 
replace stock09_2=96.72 if country==2 
replace stock09_2=153 if country==3 
replace stock09_2=146.6 if country==4 
replace stock09_2=133.14 if country==5 
replace stock09_2=417 if country==6 
replace stock09_2=157.84 if country==7 
replace stock09_2=283.02 if country==8
replace stock09_2=49.32 if country==9 
replace stock09_2=199.8 if country==10 
replace stock09_2=68.76 if country==11 
replace stock09_2=114.13 if country==12
replace stock09_2=156.55 if country==13 
replace stock09_2=207.69 if country==14
replace stock09_2=166.47 if country==15
replace stock09_2=274.25 if country==16
replace stock09_2=177.41 if country==17 
replace stock09_2=96.72 if country==18
replace stock09_2=14.7 if country==19
replace stock09_2=361.93 if country==20
replace stock09_2=42.83 if country==21
replace stock09_2=324.5 if country==22
replace stock09_2=. if country==23
replace stock09_2=77.9 if country==24
label variable stock09_2 "Democratic Stock in 2009 only compulting Third Wave years"



*** Press Freedom Index 2009 (reporters without borders)

generate pfreeinv2009=0 if country==1 
replace pfreeinv2009=18.75 if country==2 
replace pfreeinv2009=31 if country==3 
replace pfreeinv2009=6.25 if country==4 
replace pfreeinv2009=31.5 if country==5 
replace pfreeinv2009=40.25 if country==6 
replace pfreeinv2009=33.75 if country==7 
replace pfreeinv2009=8.12 if country==8
replace pfreeinv2009=28.25 if country==9 
replace pfreeinv2009=24.08 if country==10 
replace pfreeinv2009=27.37 if country==11 
replace pfreeinv2009=33.92 if country==12
replace pfreeinv2009=37.75 if country==13 
replace pfreeinv2009=40.62 if country==14
replace pfreeinv2009=32.37 if country==15
replace pfreeinv2009=8.75 if country==16
replace pfreeinv2009=36.92 if country==17 
replace pfreeinv2009=21.42 if country==18
replace pfreeinv2009=33.25 if country==19
replace pfreeinv2009=43.5 if country==20
replace pfreeinv2009=37.75 if country==21
replace pfreeinv2009=41.25 if country==22
replace pfreeinv2009=43.5 if country==23
replace pfreeinv2009=37.65 if country==24
label variable pfreeinv2009 "Press Freedom 2009 Inverted"

*** Number of Provinces

generate numbprovince=32 if country==1 
replace numbprovince=22 if country==2
replace numbprovince=14 if country== 3
replace numbprovince=18 if country==4
replace numbprovince=17 if country==5
replace numbprovince=7 if country==6
replace numbprovince=14 if country==7
replace numbprovince=32 if country==8
replace numbprovince=24 if country==9
replace numbprovince=9 if country==10
replace numbprovince=24 if country==11
replace numbprovince=17 if country==12
replace numbprovince=15 if country==13
replace numbprovince=19 if country==14
replace numbprovince=27 if country==15
replace numbprovince=23 if country==16
replace numbprovince=24 if country==17
replace numbprovince=32 if country==18 
replace numbprovince=10 if country==19
replace numbprovince=60 if country==20
replace numbprovince=10 if country==21
replace numbprovince=8 if country==22
replace numbprovince=31 if country==23
replace numbprovince=10 if country==24
label variable numbprovince "Number of Provinces"

*** Round number of provinces

gen roundnumber=country
recode roundnumber (19 20 21 24=1) (else=0)
label variable roundnumber "Round number of provinces"

*** Federal System

gen federal=country
recode federal (1 15 16 17=1) (else=0)
label variable federal "Federal System"

gen unitary = 1 - federal
label variable unitary "Unitary System"

*** Duration of Term (two binary variables: one for 5 years and other for 6 years)

gen fiveyears=country
recode fiveyears (3 5 7 10 11 12 14 19 20 21 22 23 24=1) (else=0)
label variable fiveyears "5 years of presidential term"

gen sixyears=country
recode sixyears (1 16=1) (else=0)
label variable sixyears "6 years of presidential term"

gen fivesixyears =country
recode fivesixyears (1 3 5 7 10 11 12 14 16 19 20 21 22 23 24=1) (else=0)
label variable fivesixyears "5 or 6 years of presidential term"


*** Area of the Country (in squared kilometers)

generate countryarea=1964375 if country==1 
replace countryarea=108889 if country==2
replace countryarea=21041 if country== 3
replace countryarea=112492 if country==4
replace countryarea=130373 if country==5
replace countryarea=51100 if country==6
replace countryarea=75420 if country==7
replace countryarea=1138914 if country==8
replace countryarea=283561 if country==9
replace countryarea=1098581 if country==10
replace countryarea=1285216 if country==11
replace countryarea=406752 if country==12
replace countryarea=756102 if country==13
replace countryarea=17215 if country==14
replace countryarea=8514877 if country==15
replace countryarea=915050 if country==16
replace countryarea=2780400 if country==17
replace countryarea=48670 if country==18
replace countryarea=27750 if country==19
replace countryarea=10991 if country==20
replace countryarea=214969 if country==21
replace countryarea=5128 if country==22
replace countryarea=22966 if country==23
replace countryarea=163820 if country==24
label variable countryarea "Country Area"

*** Last change in territorial divisions

generate lastchangeprov=93 if country==1 
replace lastchangeprov=185 if country==2
replace lastchangeprov=27 if country== 3
replace lastchangeprov=53 if country==4
replace lastchangeprov=24 if country==5
replace lastchangeprov=108 if country==6
replace lastchangeprov=31 if country==7
replace lastchangeprov=19 if country==8
replace lastchangeprov=3 if country==9
replace lastchangeprov=15 if country==10
replace lastchangeprov=30 if country==11
replace lastchangeprov=18 if country==12
replace lastchangeprov=3 if country==13
replace lastchangeprov=126 if country==14
replace lastchangeprov=22 if country==15
replace lastchangeprov=12 if country==16
replace lastchangeprov=20 if country==17
replace lastchangeprov=74 if country==18
replace lastchangeprov=7 if country==19
replace lastchangeprov=48 if country==20
replace lastchangeprov=24 if country==21
replace lastchangeprov=18 if country==22
replace lastchangeprov=29 if country==23
replace lastchangeprov=30 if country==24
label variable lastchangeprov "Time of last change in divisions"

*** Existence of territorial claim

gen claim=country
recode claim (12 1 17=1) (else=0)
label variable claim "Territorial claim"

*** Immediate re election

gen reelection=country
recode reelection (8 9 10 15 16 17=1) (else=0)
label variable reelection "Immediate Reelection"

*** Parliamentary countries

gen parliamentary=country
recode parliamentary (20 22 23=1) (else=0)
label variable parliamentary "Parliamentarism"

*** Central America and Caribbean

gen centralamerica=country
recode centralamerica (1 2 3 4 5 6 7=1) (else=0)
label variable centralamerica "Central America"

gen caribbean=country
recode caribbean (18 19 20 21 22 23 24=1) (else=0)
label variable caribbean "Caribbean"

*** Distance in months from last presidential election

generate lastelection=46 if country==1 
replace lastelection=29 if country==2
replace lastelection=14 if country== 3
replace lastelection=6 if country==4
replace lastelection=41 if country==5
replace lastelection=3 if country==6
replace lastelection=12 if country==7
replace lastelection=0 if country==8
replace lastelection=13 if country==9
replace lastelection=4 if country==10
replace lastelection=47 if country==11
replace lastelection=25 if country==12
replace lastelection=4 if country==13
replace lastelection=6 if country==14
replace lastelection=42 if country==15
replace lastelection=40 if country==16
replace lastelection=30 if country==17
replace lastelection=24 if country==18
replace lastelection=51 if country==19
replace lastelection=31 if country==20
replace lastelection=45 if country==21
replace lastelection=29 if country==22
replace lastelection=27 if country==23
replace lastelection=0 if country==24
label variable lastelection "Distance from last presidential elections"


*** GDP Index

generate gdpind=0.826 if country==1 
replace gdpind=0.638 if country==2
replace gdpind=0.678 if country==3
replace gdpind=0.607 if country==4
replace gdpind=0.542 if country==5
replace gdpind=0.782 if country==6
replace gdpind=0.79 if country==7
replace gdpind=0.743 if country==8
replace gdpind=0.719 if country==9
replace gdpind=0.624 if country==10
replace gdpind=0.728 if country==11
replace gdpind=0.633 if country==12
replace gdpind=0.823 if country==13
replace gdpind=0.788 if country==14
replace gdpind=0.761 if country==15
replace gdpind=0.801 if country==16
replace gdpind=0.815 if country==17
replace gdpind=0.702 if country==18
replace gdpind=0.408 if country==19
replace gdpind=0.686 if country==20
replace gdpind=0.555 if country==21
replace gdpind=0.911 if country==22
replace gdpind=0.703 if country==23
replace gdpind=0.727 if country==24
label variable gdpind "GDP Index"


*** HDI 2010

generate hdi10=0.750 if country==1 
replace hdi10=0.560 if country==2
replace hdi10=0.659 if country==3
replace hdi10=0.604 if country==4
replace hdi10=0.565 if country==5
replace hdi10=0.725 if country==6
replace hdi10=0.755 if country==7
replace hdi10=0.689 if country==8
replace hdi10=0.695 if country==9
replace hdi10=0.643 if country==10
replace hdi10=0.723 if country==11
replace hdi10=0.640 if country==12
replace hdi10=0.783 if country==13
replace hdi10=0.765 if country==14
replace hdi10=0.699 if country==15
replace hdi10=0.696 if country==16
replace hdi10=0.775 if country==17
replace hdi10=0.663 if country==18
replace hdi10=0.404 if country==19
replace hdi10=0.688 if country==20
replace hdi10=0.611 if country==21
replace hdi10=0.736 if country==22
replace hdi10=0.694 if country==23
replace hdi10=0.646 if country==24
label variable hdi10 "Human Development Index, 2010"


*** Electoral rule (LAPOP second level data)

gen fptp=country
recode fptp (20 22 23=1) (else=0)
label variable fptp "First-past-the-post"

gen fptp2 = country
recode fptp2 (1 10 16 19 20 22 24=1) (else=0)
label variable fptp2 "First-past-the-post (including mixed family)"


*** Parliamentary Structure (LAPOP second level data)

gen unicameral=country
recode unicameral (1 8 10 12 13 14 15 17 18 19 20 22 23=0) (else=1)
label variable unicameral "Unicameral System"

*** Effective Number of Legislative Parties (from Professor Michael Gallager's homepage)

generate effparties=3.03 if country==1 
replace effparties=4.88 if country==2 
replace effparties=2.94 if country==3 
replace effparties=2.3 if country==4 
replace effparties=3.14 if country==5 
replace effparties=3.32 if country==6 
replace effparties=3.69 if country==7 
replace effparties=7.19 if country==8
replace effparties=3.75 if country==9 
replace effparties=1.85 if country==10 
replace effparties=3.78 if country==11 
replace effparties=3.42 if country==12
replace effparties=2.17 if country==13 
replace effparties=2.65 if country==14
replace effparties=9.29 if country==15
replace effparties=1.07 if country==16
replace effparties=6.01 if country==17 
replace effparties=2.38 if country==18
replace effparties=8.09 if country==19
replace effparties=1.98 if country==20
replace effparties=2.34 if country==21
replace effparties=1.87 if country==22 
replace effparties=1.45 if country==23
replace effparties=3.2 if country==24
label variable effparties "Effective Number of Parties"

*** Ethnic Fractionalization (Alesina et al)

generate ethnicf=0.5414 if country==1 
replace ethnicf=0.5122 if country==2 
replace ethnicf=0.1978 if country==3 
replace ethnicf=0.1867 if country==4 
replace ethnicf=0.4844 if country==5 
replace ethnicf=0.2368 if country==6 
replace ethnicf=0.5528 if country==7 
replace ethnicf=0.6014 if country==8
replace ethnicf=0.655 if country==9 
replace ethnicf=0.7396 if country==10 
replace ethnicf=0.6566 if country==11 
replace ethnicf=0.1689 if country==12
replace ethnicf=0.1861 if country==13 
replace ethnicf=0.2504 if country==14
replace ethnicf=0.5408 if country==15
replace ethnicf=0.4966 if country==16
replace ethnicf=0.255 if country==17 
replace ethnicf=0.4294 if country==18
replace ethnicf=0.095 if country==19
replace ethnicf=0.4129 if country==20
replace ethnicf=0.6195 if country==21
replace ethnicf=0.6475 if country==22 
replace ethnicf=0.7015 if country==23
replace ethnicf=0.7332 if country==24
label variable ethnicf "Ethnic Fractionalization"


*** Linguistic Fractionalization (Alesina et al)

generate languagef=0.1511 if country==1 
replace languagef=0.4586 if country==2 
replace languagef=0 if country==3 
replace languagef=0.0553 if country==4 
replace languagef=0.0473 if country==5 
replace languagef=0.0489 if country==6 
replace languagef=0.3873 if country==7 
replace languagef=0.0193 if country==8
replace languagef=0.1308 if country==9 
replace languagef=0.224 if country==10 
replace languagef=0.3358 if country==11 
replace languagef=0.5975 if country==12
replace languagef=0.1871 if country==13 
replace languagef=0.0817 if country==14
replace languagef=0.0468 if country==15
replace languagef=0.0686 if country==16
replace languagef=0.0618 if country==17 
replace languagef=0.0489 if country==18
replace languagef=0 if country==19
replace languagef=0.1098 if country==20
replace languagef=0.0688 if country==21
replace languagef=0.1251 if country==22 
replace languagef=0.6306 if country==23
replace languagef=0.331 if country==24
label variable languagef "Linguistic Fractionalization"


*** Religious Fractionalization (Alesina et al)

generate religionf=0.1796 if country==1 
replace religionf=0.3753 if country==2 
replace religionf=0.3559 if country==3 
replace religionf=0.2357 if country==4 
replace religionf=0.429 if country==5 
replace religionf=0.241 if country==6 
replace religionf=0.3338 if country==7 
replace religionf=0.1478 if country==8
replace religionf=0.1417 if country==9 
replace religionf=0.2085 if country==10 
replace religionf=0.1988 if country==11 
replace religionf=0.2123 if country==12
replace religionf=0.3841 if country==13 
replace religionf=0.3548 if country==14
replace religionf=0.6054 if country==15
replace religionf=0.135 if country==16
replace religionf=0.2236 if country==17 
replace religionf=0.241 if country==18
replace religionf=0.4704 if country==19
replace religionf=0.616 if country==20
replace religionf=0.7876 if country==21
replace religionf=0.7936 if country==22
replace religionf=0.5813 if country==23
replace religionf=0.791 if country==24
label variable religionf "Religious Fractionalization"

*** Fractionalization

gen frac = ethnicf + languagef + religionf

label variable frac "Fractionalization"

factor ethnicf languagef religionf, ml factor(1)

predict frac_factor

label variable frac_factor "Fractionalization Factor"

*** Ballot (data from Seddon et al 2002) - index: party control over access to and position on the ballot

generate ballot=0.8 if country==1 
replace ballot=0.805 if country==2 
replace ballot=0 if country==3 
replace ballot=0 if country==4 
replace ballot=0.753 if country==5 
replace ballot=0 if country==6 
replace ballot=1 if country==7 
replace ballot=1 if country==8
replace ballot=0 if country==9 
replace ballot=0.262 if country==10 
replace ballot=0 if country==11 
replace ballot=0 if country==12
replace ballot=0 if country==13 
replace ballot=1 if country==14
replace ballot=1 if country==15
replace ballot=0 if country==16
replace ballot=0 if country==17 
replace ballot=0 if country==18
replace ballot=1 if country==19
replace ballot=1 if country==20
replace ballot=0 if country==21
replace ballot=1 if country==22 
replace ballot=1 if country==23
replace ballot=0 if country==24
label variable ballot "Ballot"


*** Pool (data from Seddon et al 2002) - sharing of votes across candidates of the same partie

generate pool=1.6 if country==1 
replace pool=1.611 if country==2 
replace pool=0 if country==3 
replace pool=0 if country==4 
replace pool=1.505 if country==5 
replace pool=0 if country==6 
replace pool=0 if country==7 
replace pool=1 if country==8
replace pool=0 if country==9 
replace pool=0.523 if country==10 
replace pool=0 if country==11 
replace pool=0 if country==12
replace pool=0 if country==13 
replace pool=1 if country==14
replace pool=1 if country==15
replace pool=0 if country==16
replace pool=0 if country==17 
replace pool=1 if country==18
replace pool=2 if country==19
replace pool=2 if country==20
replace pool=0 if country==21
replace pool=2 if country==22 
replace pool=2 if country==23
replace pool=0 if country==24
label variable pool "Pool"


*** Vote (data from Seddon et al 2002) - index: candidate or party specific voting

generate vote=1.6 if country==1 
replace vote=1.611 if country==2 
replace vote=0 if country==3 
replace vote=0 if country==4 
replace vote=1.505 if country==5 
replace vote=0 if country==6 
replace vote=2 if country==7 
replace vote=0 if country==8
replace vote=0 if country==9 
replace vote=0.523 if country==10 
replace vote=0 if country==11 
replace vote=0 if country==12
replace vote=0 if country==13 
replace vote=2 if country==14
replace vote=1 if country==15
replace vote=0 if country==16
replace vote=0 if country==17 
replace vote=1 if country==18
replace vote=1 if country==19
replace vote=2 if country==20
replace vote=0 if country==21
replace vote=2 if country==22 
replace vote=2 if country==23
replace vote=0 if country==24
label variable vote "Vote"

* presonal vote

gen personalvote = (ballot + pool + vote)/6

label variable personalvote "Incentives for Personal Vote, additive scale"

factor ballot pool vote, ml factor(1)

predict personalvote_factor

label variable personalvote_factor "Incentives for Personal Vote, factor scores"


*** age of parties weighted by their seat share in lower chamber � only 6 main parties based on Huber, Kernell & Leoni (data collected by me)

generate w_age_HKL=64.116 if country==1 
replace w_age_HKL=8.293 if country==2 
replace w_age_HKL=28 if country==3 
replace w_age_HKL=104.883 if country==4 
replace w_age_HKL=33.717 if country==5 
replace w_age_HKL=33.14 if country==6 
replace w_age_HKL=38.641 if country==7 
replace w_age_HKL=66.5 if country==8
replace w_age_HKL=5.274 if country==9 
replace w_age_HKL=10.692 if country==10 
replace w_age_HKL=34.167 if country==11 
replace w_age_HKL=58.863 if country==12
replace w_age_HKL=31.342 if country==13 
replace w_age_HKL=102.444 if country==14
replace w_age_HKL=22.505 if country==15
replace w_age_HKL=17.216 if country==16
replace w_age_HKL=24.996 if country==17 
replace w_age_HKL=47 if country==18
replace w_age_HKL=4.02 if country==19
replace w_age_HKL=69.205 if country==20
replace w_age_HKL=52.323 if country==21
replace w_age_HKL=42.561 if country==22
replace w_age_HKL=41.452 if country==23
replace w_age_HKL=33.064 if country==24
label variable w_age_HKL "Weighted party age HKL"


*** GDP per capita 2009 (World Bank)

generate gdppc2009=7596 if country==1 
replace gdppc2009=2697 if country==2 
replace gdppc2009=3341 if country==3 
replace gdppc2009=1897 if country==4 
replace gdppc2009=1420 if country==5 
replace gdppc2009=6386 if country==6 
replace gdppc2009=6683 if country==7 
replace gdppc2009=5105 if country==8
replace gdppc2009=4237 if country==9 
replace gdppc2009=1735 if country==10 
replace gdppc2009=4387 if country==11 
replace gdppc2009=2514 if country==12
replace gdppc2009=10120 if country==13 
replace gdppc2009=8996 if country==14
replace gdppc2009=8373 if country==15
replace gdppc2009=11525 if country==16
replace gdppc2009=7674 if country==17 
replace gdppc2009=4726 if country==18
replace gdppc2009=663 if country==19
replace gdppc2009=4477 if country==20
replace gdppc2009=2593 if country==21
replace gdppc2009=14557 if country==22
replace gdppc2009=4481 if country==23
replace gdppc2009=7450 if country==24
label variable gdppc2009 "GDP pc 2009 (WB)"

gen gdpover1000 = gdppc2009/1000

label variable gdpover1000 "GDP pc 2009 (WB) ober 1000"

*** GDP annual growth in 2009 (World Bank)

generate growth09=-6.5 if country==1 
replace growth09=0.6 if country==2 
replace growth09=-3.1 if country==3 
replace growth09=-5.6 if country==4 
replace growth09=-1.5 if country==5 
replace growth09=2.4 if country==6 
replace growth09=0.8 if country==7 
replace growth09=0.4 if country==8
replace growth09=3.4 if country==9 
replace growth09=0.9 if country==10 
replace growth09=-3.8 if country==11 
replace growth09=2514 if country==12
replace growth09=-1.5 if country==13 
replace growth09=2.9 if country==14
replace growth09=-0.6 if country==15
replace growth09=-3.3 if country==16
replace growth09=0.9 if country==17 
replace growth09=3.5 if country==18
replace growth09=2.9 if country==19
replace growth09=-3 if country==20
replace growth09=3.3 if country==21
replace growth09=-3 if country==22
replace growth09=0 if country==23
replace growth09=5.1 if country==24
label variable growth09 "GDP annual growth 2009 (WB)"


*** GINI Index 2009 (World Bank)

generate gini2009=0.481 if country==1 
replace gini2009=0.537 if country==2 
replace gini2009=0.497 if country==3 
replace gini2009=0.553 if country==4 
replace gini2009=0.523 if country==5 
replace gini2009=0.472 if country==6 
replace gini2009=0.549 if country==7 
replace gini2009=0.595 if country==8
replace gini2009=0.544 if country==9 
replace gini2009=0.582 if country==10 
replace gini2009=0.496 if country==11 
replace gini2009=0.532 if country==12
replace gini2009=0.52 if country==13 
replace gini2009=0.462 if country==14
replace gini2009=0.55 if country==15
replace gini2009=0.434 if country==16
replace gini2009=0.5 if country==17 
replace gini2009=0.5 if country==18
replace gini2009=0.595 if country==19
replace gini2009=0.455 if country==20
replace gini2009=0.446 if country==21
replace gini2009=0.403 if country==22
replace gini2009=0.492 if country==23
replace gini2009=0.529 if country==24
label variable gini2009 "GINI Index 2009 (WB)"


gen gini09 = (gini2009 - .403)/(.192)

label variable gini09 "GINI Index re-scaled from 0 minimum to 1 maximum"


*** Compulsory Voting Systems (LAPOP second level data)

gen compulsory=country
recode compulsory (4 6 9 10 11 12 14 15 16 17 18=1) (else=0)
label variable compulsory "Compulsory Vote"


*** Women Political Empowerment Index 2010 (World Economic Forum)

generate wpei2010=0.139 if country==1 
replace wpei2010=0.042 if country==2 
replace wpei2010=0.1178 if country==3 
replace wpei2010=0.2052 if country==4 
replace wpei2010=0.3037 if country==5 
replace wpei2010=0.3287 if country==6 
replace wpei2010=0.1677 if country==7 
replace wpei2010=0.1018 if country==8
replace wpei2010=0.2665 if country==9 
replace wpei2010=0.1735 if country==10 
replace wpei2010=0.1926 if country==11 
replace wpei2010=0.1129 if country==12
replace wpei2010=0.2957 if country==13 
replace wpei2010=0.1227 if country==14
replace wpei2010=0.0488 if country==15
replace wpei2010=0.1521 if country==16
replace wpei2010=0.2976 if country==17 
replace wpei2010=0.087 if country==18
replace wpei2010=0.067 if country==19
replace wpei2010=0.0967 if country==20
replace wpei2010=0.2674 if country==21
replace wpei2010=0.2549 if country==22
replace wpei2010=0 if country==23
replace wpei2010=0.1539 if country==24
label variable wpei2010 "Women Political Emporwerment Index 2010"



*** Gender Gap Index 2010 (World Economic Forum)

generate ggi2010=0.6577 if country==1 
replace ggi2010=0.6238 if country==2 
replace ggi2010=0.6596 if country==3 
replace ggi2010=0.6927 if country==4 
replace ggi2010=0.7176 if country==5 
replace ggi2010=0.7194 if country==6 
replace ggi2010=0.7072 if country==7 
replace ggi2010=0.6927 if country==8
replace ggi2010=0.7072 if country==9 
replace ggi2010=0.6751 if country==10 
replace ggi2010=0.6895 if country==11 
replace ggi2010=0.6804 if country==12
replace ggi2010=0.7013 if country==13 
replace ggi2010=0.6897 if country==14
replace ggi2010=0.6655 if country==15
replace ggi2010=0.6863 if country==16
replace ggi2010=0.7187 if country==17 
replace ggi2010=0.6774 if country==18
replace ggi2010=. if country==19
replace ggi2010=0.7037 if country==20
replace ggi2010=0.7090 if country==21
replace ggi2010=0.7353 if country==22 
replace ggi2010=0.6536 if country==23
replace ggi2010=0.6407 if country==24
label variable ggi2010 "Gender Gap Index 2010"

*** Social spending as % of GDP (2008), from ECLAC database

generate socspen08=9.99 if country==1 
replace socspen08=7 if country==2 
replace socspen08=12.31 if country==3 
replace socspen08=10.72 if country==4 
replace socspen08=12.28 if country==5 
replace socspen08=19.31 if country==6 
replace socspen08=9.28 if country==7 
replace socspen08=12.59 if country==8
replace socspen08=7.3 if country==9 
replace socspen08=18.42 if country==10 
replace socspen08=8.71 if country==11 
replace socspen08=8.4 if country==12
replace socspen08=14.11 if country==13 
replace socspen08=21.65 if country==14
replace socspen08=24.83 if country==15
replace socspen08=. if country==16
replace socspen08=23.98 if country==17 
replace socspen08=8.55 if country==18
replace socspen08=. if country==19
replace socspen08=10.75 if country==20
replace socspen08=. if country==21
replace socspen08=12.06 if country==22 
replace socspen08=. if country==23
replace socspen08=. if country==24
label variable socspen08 "Social spending 2008 as % of GDP (ECLAC)"

gen socspen08_2 = socspen08

recode socspen08_2 (.=13.50399)

label variable socspen08_2 "Social spending 2008 with mean imputed"


*** Droughts, floods, extreme temperatures (% of population, average 1990-2009)

generate geography09=0.15 if country==1 
replace geography09=1.31 if country==2 
replace geography09=0.36 if country==3 
replace geography09=1.26 if country==4 
replace geography09=0.83 if country==5 
replace geography09=0.70 if country==6 
replace geography09=0.20 if country==7 
replace geography09=0.66 if country==8
replace geography09=0.34 if country==9 
replace geography09=1.30 if country==10 
replace geography09=1.95 if country==11 
replace geography09=0.71 if country==12
replace geography09=0.26 if country==13 
replace geography09=0.26 if country==14
replace geography09=0.48 if country==15
replace geography09=0.16 if country==16
replace geography09=0.17 if country==17 
replace geography09=0.08 if country==18
replace geography09=0.84 if country==19
replace geography09=1.14 if country==20
replace geography09=7.17 if country==21
replace geography09=0.00 if country==22 
replace geography09=0.81 if country==23
replace geography09=0.34 if country==24
label variable geography09 "Droughts, floods, extreme temperatures (% of population, average 1990-2009)"

*** Fuel exports (% of merchandise exports)

generate fuel09=13.51 if country==1 
replace fuel09=4.07 if country==2 
replace fuel09=2.81 if country==3 
replace fuel09=4.31 if country==4 
replace fuel09=0.86 if country==5 
replace fuel09=0.57 if country==6 
replace fuel09=0.91 if country==7 
replace fuel09=50.72 if country==8
replace fuel09=49.82 if country==9 
replace fuel09=40.01 if country==10 
replace fuel09=10.35 if country==11 
replace fuel09=0.01 if country==12
replace fuel09=1.37 if country==13 
replace fuel09=1.41 if country==14
replace fuel09=9.00 if country==15
replace fuel09=95.90 if country==16
replace fuel09=10.34 if country==17 
replace fuel09=0.04 if country==18
replace fuel09=. if country==19
replace fuel09=17.24 if country==20
replace fuel09=0.00 if country==21
replace fuel09=79.00 if country==22 
replace fuel09=27.97 if country==23
replace fuel09=4.50 if country==24
label variable fuel09 "Fuel exports (% of merchandise exports)� 

*** Merchandise imports from high-income economies (% of total merchandise imports)

generate mercha09=76.74 if country==1 
replace mercha09=57.57 if country==2 
replace mercha09=50.26 if country==3 
replace mercha09=48.80 if country==4 
replace mercha09=35.90 if country==5 
replace mercha09=65.18 if country==6 
replace mercha09=44.85 if country==7 
replace mercha09=57.53 if country==8
replace mercha09=52.54 if country==9 
replace mercha09=49.71 if country==10 
replace mercha09=48.39 if country==11 
replace mercha09=21.34 if country==12
replace mercha09=48.54 if country==13 
replace mercha09=30.40 if country==14
replace mercha09=59.87 if country==15
replace mercha09=50.79 if country==16
replace mercha09=40.75 if country==17 
replace mercha09=69.01 if country==18
replace mercha09=51.62 if country==19
replace mercha09=66.30 if country==20
replace mercha09=74.25 if country==21
replace mercha09=65.02 if country==22 
replace mercha09=60.51 if country==23
replace mercha09=80.03 if country==24
label variable mercha09 "Merchandise imports from high-income economies (% of total merchandise imports)� 

*** Trade (% of GDP), 2009

generate trade09=56.71 if country==1 
replace trade09=57.11 if country==2 
replace trade09=61.87 if country==3 
replace trade09=96.91 if country==4 
replace trade09=78.03 if country==5 
replace trade09=83.97 if country==6 
replace trade09=144.86 if country==7 
replace trade09=34.28 if country==8
replace trade09=52.10 if country==9 
replace trade09=68.63 if country==10 
replace trade09=44.37 if country==11 
replace trade09=96.05 if country==12
replace trade09=66.87 if country==13 
replace trade09=65.20 if country==14
replace trade09=22.12 if country==15
replace trade09=38.52 if country==16
replace trade09=37.35 if country==17 
replace trade09=52.50 if country==18
replace trade09=56.97 if country==19
replace trade09=86.67 if country==20
replace trade09=. if country==21
replace trade09=90.12 if country==22 
replace trade09=33.35 if country==23
replace trade09=. if country==24
label variable trade09 "Trade (% of GDP), 2009� 

*** MacDonald�s stores per capita (*1,000,000)

generate macdonalds=33.33 if country==1 
replace macdonalds=4.97 if country==2 
replace macdonalds=1.91 if country==3 
replace macdonalds=1.39 if country==4 
replace macdonalds=1.00 if country==5 
replace macdonalds=10.41 if country==6 
replace macdonalds=13.68 if country==7 
replace macdonalds=1.57 if country==8
replace macdonalds=1.36 if country==9 
replace macdonalds=0 if country==10 
replace macdonalds=0.97 if country==11 
replace macdonalds=2.24 if country==12
replace macdonalds=4.41 if country==13 
replace macdonalds=7.07 if country==14
replace macdonalds=3.68 if country==15
replace macdonalds=5.11 if country==16
replace macdonalds=5.09 if country==17 
replace macdonalds=0.97 if country==18
replace macdonalds=0 if country==19
replace macdonalds=0 if country==20
replace macdonalds=0 if country==21
replace macdonalds=2.26 if country==22
replace macdonalds=0 if country==23
replace macdonalds=3.74 if country==24
label variable macdonalds "MacDonald�s stores per capita (*1,000,000)"

** Distance in kilometers from capital to most southern US border (Brownsville, tx)

generate usdistance=845.3 if country==1 
replace usdistance=1544 if country==2 
replace usdistance=1701 if country==3 
replace usdistance=1779 if country==4 
replace usdistance=2017 if country==5 
replace usdistance=2353 if country==6 
replace usdistance=2746 if country==7 
replace usdistance=3510 if country==8
replace usdistance=3633 if country==9 
replace usdistance=6175 if country==10 
replace usdistance=4860 if country==11 
replace usdistance=7204 if country==12
replace usdistance=7285 if country==13 
replace usdistance=8127 if country==14
replace usdistance=6716 if country==15
replace usdistance=3684 if country==16
replace usdistance=7981 if country==17 
replace usdistance=2970 if country==18
replace usdistance=2737 if country==19
replace usdistance=2342 if country==20
replace usdistance=4713 if country==21
replace usdistance=4174 if country==22
replace usdistance=1398 if country==23
replace usdistance=5046 if country==24
label variable usdistance "Distance in kilometers from most southern US border (Brownsville, tx)"


* Dummy for English speaking countries

recode country (20 21 22 23=1) (else=0), gen(english)

label variable english "English speaking countries"


*** International migrant stock (% of population) - 2010

generate migstock10=0.62 if country==1 
replace migstock10=0.41 if country==2 
replace migstock10=0.65 if country==3 
replace migstock10=0.32 if country==4 
replace migstock10=0.69 if country==5 
replace migstock10=10.48 if country==6 
replace migstock10=3.29 if country==7 
replace migstock10=0.24 if country==8
replace migstock10=2.62 if country==9 
replace migstock10=1.44 if country==10 
replace migstock10=0.13 if country==11 
replace migstock10=2.50 if country==12
replace migstock10=1.87 if country==13 
replace migstock10=2.37 if country==14
replace migstock10=0.35 if country==15
replace migstock10=3.47 if country==16
replace migstock10=3.59 if country==17 
replace migstock10=4.34 if country==18
replace migstock10=0.35 if country==19
replace migstock10=1.11 if country==20
replace migstock10=1.48 if country==21
replace migstock10=2.59 if country==22 
replace migstock10=15.17 if country==23
replace migstock10=7.52 if country==24
label variable migstock10 "International migrant stock (% of population) - 2010� 


*** Access to electricity (% of population), 2009

generate electricity09=. if country==1 
replace electricity09=80.5 if country==2 
replace electricity09=86.4 if country==3 
replace electricity09=70.3 if country==4 
replace electricity09=72.1 if country==5 
replace electricity09=99.3 if country==6 
replace electricity09=88.1 if country==7 
replace electricity09=93.6 if country==8
replace electricity09=92.2 if country==9 
replace electricity09=77.5 if country==10 
replace electricity09=85.7 if country==11 
replace electricity09=96.7 if country==12
replace electricity09=98.5 if country==13 
replace electricity09=98.3 if country==14
replace electricity09=98.3 if country==15
replace electricity09=99 if country==16
replace electricity09=97.2 if country==17 
replace electricity09=95.9 if country==18
replace electricity09=38.5 if country==19
replace electricity09=92 if country==20
replace electricity09=. if country==21
replace electricity09=99 if country==22 
replace electricity09=. if country==23
replace electricity09=. if country==24
label variable electricity09 "Access to electricity (% of population), 2009� 


*** Electric power consumption (kWh per capita), 2009

generate powercons09=1869.82 if country==1 
replace powercons09=549.79 if country==2 
replace powercons09=842.73 if country==3 
replace powercons09=673.64 if country==4 
replace powercons09=476.20 if country==5 
replace powercons09=1812.92 if country==6 
replace powercons09=1663.23 if country==7 
replace powercons09=1041.99 if country==8
replace powercons09=1078.04 if country==9 
replace powercons09=546.16 if country==10 
replace powercons09=1043.05 if country==11 
replace powercons09=1055.08 if country==12
replace powercons09=3276.06 if country==13 
replace powercons09=2661.56 if country==14
replace powercons09=2201.81 if country==15
replace powercons09=3031.27 if country==16
replace powercons09=2761.44 if country==17 
replace powercons09=812.60 if country==18
replace powercons09=36.05 if country==19
replace powercons09=1904.59 if country==20
replace powercons09=. if country==21
replace powercons09=5720.91 if country==22 
replace powercons09=. if country==23
replace powercons09=. if country==24
label variable powercons09 "Electric power consumption (kWh per capita), 2009� 


*** Foreign direct investment, net inflows (% of GDP), 2009

generate fdi09=1.87 if country==1 
replace fdi09=1.85 if country==2 
replace fdi09=1.78 if country==3 
replace fdi09=3.39 if country==4 
replace fdi09=5.32 if country==5 
replace fdi09=4.58 if country==6 
replace fdi09=4.49 if country==7 
replace fdi09=3.05 if country==8
replace fdi09=0.51 if country==9 
replace fdi09=2.44 if country==10 
replace fdi09=5.07 if country==11 
replace fdi09=1.17 if country==12
replace fdi09=7.50 if country==13 
replace fdi09=5.30 if country==14
replace fdi09=1.94 if country==15
replace fdi09=-0.78 if country==16
replace fdi09=1.31 if country==17 
replace fdi09=3.63 if country==18
replace fdi09=0.59 if country==19
replace fdi09=4.02 if country==20
replace fdi09=10.27 if country==21
replace fdi09=3.68 if country==22 
replace fdi09=8.07 if country==23
replace fdi09=-2.41 if country==24
label variable fdi09 "Foreign direct investment, net inflows (% of GDP), 2009� 

*** International tourism, receipts (% of total exports), 2009

generate tourism09=5.13 if country==1 
replace tourism09=12.79 if country==2 
replace tourism09=13.02 if country==3 
replace tourism09=14.51 if country==4 
replace tourism09=12.07 if country==5 
replace tourism09=20.69 if country==6 
replace tourism09=12.99 if country==7 
replace tourism09=7.04 if country==8
replace tourism09=4.28 if country==9 
replace tourism09=5.64 if country==10 
replace tourism09=8.03 if country==11 
replace tourism09=3.09 if country==12
replace tourism09=3.67 if country==13 
replace tourism09=516.80 if country==14
replace tourism09=3.12 if country==15
replace tourism09=1.76 if country==16
replace tourism09=6.73 if country==17 
replace tourism09=39.24 if country==18
replace tourism09=33.55 if country==19
replace tourism09=51.26 if country==20
replace tourism09=3.73 if country==21
replace tourism09=5.50 if country==22 
replace tourism09=35.15 if country==23
replace tourism09=4.15 if country==24
label variable tourism09 "International tourism, receipts (% of total exports), 2009� 


*** Investment in telecoms with private participation (current US$), 2009

generate telecoms09=2544900000 if country==1 
replace telecoms09=206300000 if country==2 
replace telecoms09=87100000 if country==3 
replace telecoms09=276600000 if country==4 
replace telecoms09=52900000 if country==5 
replace telecoms09=. if country==6 
replace telecoms09=115500000 if country==7 
replace telecoms09=899700000 if country==8
replace telecoms09=259100000 if country==9 
replace telecoms09=37400000 if country==10 
replace telecoms09=683800000 if country==11 
replace telecoms09=92900000 if country==12
replace telecoms09=365300000 if country==13 
replace telecoms09=44700000 if country==14
replace telecoms09=7135600000 if country==15
replace telecoms09=545800000 if country==16
replace telecoms09=1319400000 if country==17 
replace telecoms09=110000000 if country==18
replace telecoms09=0 if country==19
replace telecoms09=5400000 if country==20
replace telecoms09=0 if country==21
replace telecoms09=. if country==22 
replace telecoms09=. if country==23
replace telecoms09=0 if country==24
label variable telecoms09 "Investment in telecoms with private participation (current US$), 2009� 

gen telecoms09_nomi = telecoms09

replace telecoms09_nomi = 8.19e+08 if telecoms09_nomi ==.

label variable telecoms09_nomi "Missing Imputed - Investment in telecoms with private participation (current US$), 2009�

gen telecom09ov1000 = telecoms09_nomi/1000

label variable telecom09ov1000 "Missing Imputed - Investment in telecoms over 1000�

gen telecoms_tenmill = telecoms09_nomi/10000000

label variable telecoms_tenmill "Missing Imputed - Investment in telecoms over 1000000�


*** Average Investment in telecoms with private participation (current US$), 2000-2009, over 1000000  (Costa Rica is average of 2011 and 2012, Trinidad is 0 imputed)

generate telecoms=3138056000 if country==1 
replace telecoms=207150000 if country==2 
replace telecoms=201252000 if country==3 
replace telecoms=106546000 if country==4 
replace telecoms=66515556 if country==5 
replace telecoms=294000000 if country==6 
replace telecoms=20505714 if country==7 
replace telecoms=686560000 if country==8
replace telecoms=212250000 if country==9 
replace telecoms=80520000 if country==10 
replace telecoms=488460000 if country==11 
replace telecoms=79040000 if country==12
replace telecoms=241560000 if country==13 
replace telecoms=38957143 if country==14
replace telecoms=7199690000 if country==15
replace telecoms=595680000 if country==16
replace telecoms=1087035000 if country==17 
replace telecoms=61312000 if country==18
replace telecoms=54000000 if country==19
replace telecoms=89775000 if country==20
replace telecoms=11450000 if country==21
replace telecoms=153899000 if country==22 
replace telecoms=45000000 if country==23
replace telecoms=20000000 if country==24
label variable telecoms09 "Average Investment in telecoms with private participation, 2000-2009, in millions of US$� 

 gen telecoms_tenmill =telecoms/10000000

label variable telecoms_tenmill "Average 00-02 investiment in telecoms divided by ten million"


** GDP 2009 (US dollars

generate gdp2009=895354565566.632 if country==1 
replace gdp2009=37733791088.9585 if country==2 
replace gdp2009=20661000000 if country==3 
replace gdp2009=14486137413.5391 if country==4 
replace gdp2009=8156131183.33235 if country==5 
replace gdp2009=29382590137.6267 if country==6 
replace gdp2009=24162900000 if country==7 
replace gdp2009=234360070287.095 if country==8
replace gdp2009=62519686000 if country==9 
replace gdp2009=17339992165.2422 if country==10 
replace gdp2009=130064300617.482 if country==11 
replace gdp2009=15954961409.8569 if country==12
replace gdp2009=171956957320.499 if country==13 
replace gdp2009=30229404320.5219 if country==14
replace gdp2009=1620165226993.77 if country==15
replace gdp2009=329418979506.288 if country==16
replace gdp2009=307155148184.324 if country==17 
replace gdp2009=46768400362.8292 if country==18
replace gdp2009=6470254240.08231 if country==19
replace gdp2009=12043372132.4443 if country==20
replace gdp2009=2025565089.48272 if country==21
replace gdp2009=19251916757.9409 if country==22
replace gdp2009=1338500000 if country==23
replace gdp2009=3875409836.06557 if country==24
label variable gdp2009 "GDP 2009 in current US dollars (WB)"


*** Investment in telecoms with private participation (current US$), 2009

gen telecoms09_per = telecoms09/gdp2009

summarize telecoms09_per

replace telecoms09_per = .0037942 if telecoms09_per==.

label variable telecoms09_per "Investment in telecoms with private participation (% of GDP), 2009 (MI)"


*** Public spending on education, total (% of GDP), 2009

generate pubinvedu09=5.31 if country==1 
replace pubinvedu09=2.80 if country==2 
replace pubinvedu09=3.74 if country==3 
replace pubinvedu09=. if country==4 
replace pubinvedu09=4.66 if country==5 
replace pubinvedu09=6.28 if country==6 
replace pubinvedu09=3.83 if country==7 
replace pubinvedu09=4.75 if country==8
replace pubinvedu09=4.89 if country==9 
replace pubinvedu09=8.08 if country==10 
replace pubinvedu09=2.99 if country==11 
replace pubinvedu09=4.12 if country==12
replace pubinvedu09=4.23 if country==13 
replace pubinvedu09=. if country==14
replace pubinvedu09=5.62 if country==15
replace pubinvedu09=. if country==16
replace pubinvedu09=6.03 if country==17 
replace pubinvedu09=. if country==18
replace pubinvedu09=. if country==19
replace pubinvedu09=6.20 if country==20
replace pubinvedu09=3.36 if country==21
replace pubinvedu09=. if country==22 
replace pubinvedu09=6.12 if country==23
replace pubinvedu09=. if country==24
label variable pubinvedu09 "Public spending on education, total (% of GDP), 2009� 

gen pubinvedu09_nomi = pubinvedu09

replace pubinvedu09_nomi= 5.050315 if pubinvedu09_nomi==.

label variable pubinvedu09_nomi "Public spending on education, total (% of GDP), 2009 (misisng imputed = mean)� 



*** Pupil-teacher ratio, primary, 2009

generate pupiltea09=17.64 if country==1 
replace pupiltea09=15.99 if country==2 
replace pupiltea09=24.36 if country==3 
replace pupiltea09=. if country==4 
replace pupiltea09=28.59 if country==5 
replace pupiltea09=15.82 if country==6 
replace pupiltea09=14.66 if country==7 
replace pupiltea09=26.66 if country==8
replace pupiltea09=11.19 if country==9 
replace pupiltea09=. if country==10 
replace pupiltea09=16.53 if country==11 
replace pupiltea09=. if country==12
replace pupiltea09=22.41 if country==13 
replace pupiltea09=12.43 if country==14
replace pupiltea09=17.14 if country==15
replace pupiltea09=. if country==16
replace pupiltea09=10.90 if country==17 
replace pupiltea09=26.94 if country==18
replace pupiltea09=. if country==19
replace pupiltea09=14.55 if country==20
replace pupiltea09=21.90 if country==21
replace pupiltea09=13.52 if country==22 
replace pupiltea09=16.74 if country==23
replace pupiltea09=13.31 if country==24
label variable pupiltea09 "Pupil-teacher ratio, primary, 2009� 


*** Scientific and technical journal articles, 2009

generate articles09=4127.7 if country==1 
replace articles09=22.1 if country==2 
replace articles09=5.5 if country==3 
replace articles09=6.2 if country==4 
replace articles09=11.9 if country==5 
replace articles09=98.3 if country==6 
replace articles09=72.6 if country==7 
replace articles09=608.4 if country==8
replace articles09=67.5 if country==9 
replace articles09=45.2 if country==10 
replace articles09=158.6 if country==11 
replace articles09=11.1 if country==12
replace articles09=1867.8 if country==13 
replace articles09=246.2 if country==14
replace articles09=12306.3 if country==15
replace articles09=353.5 if country==16
replace articles09=3655.2 if country==17 
replace articles09=6.1 if country==18
replace articles09=7 if country==19
replace articles09=50.8 if country==20
replace articles09=2.8 if country==21
replace articles09=47.7 if country==22 
replace articles09=2 if country==23
replace articles09=1.1 if country==24
label variable articles09 "Scientific and technical journal articles, 2009� 

*** Telephone lines (per 100 people), 2009

generate phones09=17.41 if country==1 
replace phones09=10.07 if country==2 
replace phones09=17.84 if country==3 
replace phones09=9.62 if country==4 
replace phones09=4.46 if country==5 
replace phones09=32.67 if country==6 
replace phones09=15.49 if country==7 
replace phones09=16.37 if country==8
replace phones09=14.12 if country==9 
replace phones09=8.23 if country==10 
replace phones09=12.34 if country==11 
replace phones09=6.11 if country==12
replace phones09=21.02 if country==13 
replace phones09=28.40 if country==14
replace phones09=21.47 if country==15
replace phones09=24.08 if country==16
replace phones09=24.38 if country==17 
replace phones09=9.85 if country==18
replace phones09=1.08 if country==19
replace phones09=11.08 if country==20
replace phones09=19.53 if country==21
replace phones09=22.69 if country==22 
replace phones09=10.21 if country==23
replace phones09=16.11 if country==24
label variable phones09 "Telephone lines (per 100 people), 2009� 

*** Freedom of the Press, 2009 (Freedom House)

generate freepress09=55 if country==1 
replace freepress09=60 if country==2 
replace freepress09=42 if country==3 
replace freepress09=52 if country==4 
replace freepress09=45 if country==5 
replace freepress09=19 if country==6 
replace freepress09=44 if country==7 
replace freepress09=59 if country==8
replace freepress09=44 if country==9 
replace freepress09=42 if country==10 
replace freepress09=44 if country==11 
replace freepress09=59 if country==12
replace freepress09=29 if country==13 
replace freepress09=26 if country==14
replace freepress09=42 if country==15
replace freepress09=73 if country==16
replace freepress09=49 if country==17 
replace freepress09=40 if country==18
replace freepress09=53 if country==19
replace freepress09=15 if country==20
replace freepress09=30 if country==21
replace freepress09=23 if country==22 
replace freepress09=21 if country==23
replace freepress09=23 if country==24
label variable freepress09 "Freedom of the Press, 2009 (Freedom House)� 

gen fpressinv09 = 73 - freepress09

label variable fpressinv09 "Inverted Freedom of the Press, 2009 (FH)"


*** Gallagher Index of Disproportionality

generate disprop=10.46 if country==1 
replace disprop=9.95 if country==2 
replace disprop=3.35 if country==3 
replace disprop=2.58 if country==4 
replace disprop=5.07 if country==5 
replace disprop=4.96 if country==6 
replace disprop=. if country==7 
replace disprop=3.98 if country==8
replace disprop=4.6 if country==9 
replace disprop=3.76 if country==10 
replace disprop=8.87 if country==11 
replace disprop=5.81 if country==12
replace disprop=6.87 if country==13 
replace disprop=1.1 if country==14
replace disprop=2.5 if country==15
replace disprop=8.34 if country==16
replace disprop=4.99 if country==17 
replace disprop=4.99 if country==18
replace disprop=. if country==19
replace disprop=4.82 if country==20
replace disprop=1.08 if country==21
replace disprop=20.81 if country==22 
replace disprop=22.69 if country==23
replace disprop=7.38 if country==24
label variable disprop "Gallagher Index of Disproportionality� 

gen disprop_nomi = disprop

replace disprop_nomi = 6.443257 if disprop_nomi==.

label variable disprop_nomi "Gallagher Index of Disproportionality no missing (mean imputed)� 


*** age of parties weighted by their seat share in lower chamber � only parties with more than 1% of seats (data collected by me)

generate w_age_ab1=64.362 if country==1 
replace w_age_ab1=8.293 if country==2 
replace w_age_ab1=28 if country==3 
replace w_age_ab1=104.883 if country==4 
replace w_age_ab1=33.717 if country==5 
replace w_age_ab1=33.14 if country==6 
replace w_age_ab1=38.641 if country==7 
replace w_age_ab1=67.337 if country==8
replace w_age_ab1=8.976 if country==9 
replace w_age_ab1=10.692 if country==10 
replace w_age_ab1=34.167 if country==11 
replace w_age_ab1=58.863 if country==12
replace w_age_ab1=33.642 if country==13 
replace w_age_ab1=102.444 if country==14
replace w_age_ab1=30.246 if country==15
replace w_age_ab1=17.216 if country==16
replace w_age_ab1=30.027 if country==17 
replace w_age_ab1=47 if country==18
replace w_age_ab1=5.152 if country==19
replace w_age_ab1=69.205 if country==20
replace w_age_ab1=52.323 if country==21
replace w_age_ab1=42.561 if country==22 
replace w_age_ab1=41.561 if country==23
replace w_age_ab1=33.064 if country==24
label variable w_age_ab1 "Weighted party age"


*** average age of parties � only parties with more than 1% of seats (data collected by me)

generate mean_age=33.714 if country==1 
replace mean_age=9.4 if country==2 
replace mean_age=25.167 if country==3 
replace mean_age=65.4 if country==4 
replace mean_age=22.2 if country==5 
replace mean_age=22.167 if country==6 
replace mean_age=36 if country==7 
replace mean_age=50.143 if country==8
replace mean_age=12.4 if country==9 
replace mean_age=30.25 if country==10 
replace mean_age=20.143 if country==11 
replace mean_age=22.5 if country==12
replace mean_age=38.875 if country==13 
replace mean_age=98.5 if country==14
replace mean_age=32.846 if country==15
replace mean_age=20.333 if country==16
replace mean_age=32.071 if country==17 
replace mean_age=51.667 if country==18
replace mean_age=8.071 if country==19
replace mean_age=69.5 if country==20
replace mean_age=33.6 if country==21
replace mean_age=38 if country==22
replace mean_age=48.5 if country==23
replace mean_age=26.55 if country==24
label variable mean_age "Mean party age"


*** number of electoral parties � only parties with more than 1% of seats following Huber, Kernell and, Leoni(data collected by me)

generate numbpartiesHKL=7 if country==1 
replace numbpartiesHKL=10 if country==2 
replace numbpartiesHKL=6 if country==3 
replace numbpartiesHKL=5 if country==4 
replace numbpartiesHKL=4 if country==5 
replace numbpartiesHKL=8 if country==6 
replace numbpartiesHKL=6 if country==7 
replace numbpartiesHKL=13 if country==8
replace numbpartiesHKL=10 if country==9 
replace numbpartiesHKL=4 if country==10 
replace numbpartiesHKL=7 if country==11 
replace numbpartiesHKL=8 if country==12
replace numbpartiesHKL=8 if country==13 
replace numbpartiesHKL=4 if country==14
replace numbpartiesHKL=13 if country==15
replace numbpartiesHKL=6 if country==16
replace numbpartiesHKL=14 if country==17 
replace numbpartiesHKL=3 if country==18
replace numbpartiesHKL=14 if country==19
replace numbpartiesHKL=2 if country==20
replace numbpartiesHKL=5 if country==21
replace numbpartiesHKL=2 if country==22 
replace numbpartiesHKL=2 if country==23
replace numbpartiesHKL=5 if country==24
label variable numbpartiesHKL "Number of electoral parties HKL"

*** number of electoral parties with seats in lower chamber (data collected by me)

generate numbparties_seat=7 if country==1 
replace numbparties_seat=11 if country==2 
replace numbparties_seat=6 if country==3 
replace numbparties_seat=5 if country==4 
replace numbparties_seat=4 if country==5 
replace numbparties_seat=8 if country==6 
replace numbparties_seat=6 if country==7 
replace numbparties_seat=20 if country==8
replace numbparties_seat=19 if country==9 
replace numbparties_seat=4 if country==10 
replace numbparties_seat=7 if country==11 
replace numbparties_seat=8 if country==12
replace numbparties_seat=8 if country==13 
replace numbparties_seat=4 if country==14
replace numbparties_seat=21 if country==15
replace numbparties_seat=6 if country==16
replace numbparties_seat=35 if country==17 
replace numbparties_seat=3 if country==18
replace numbparties_seat=14 if country==19
replace numbparties_seat=2 if country==20
replace numbparties_seat=5 if country==21
replace numbparties_seat=2 if country==22 
replace numbparties_seat=2 if country==23
replace numbparties_seat=5 if country==24
label variable numbparties_seat "Number of electoral parties

* Constructs of Clarity of Responsibility/system complexity

gen partyclarity = 1 - (effparties - 1.07)/(8.22)

label variable partyclarity "Inverted 0 to 1 Number of effective parties"

factor fptp2 partyclarity disprop_nomi, ml factor(1)

predict clarity_factor3

label variable clarity_factor3 "ML factor of clarity with fptp2, partyclarity and disprop_nomi"

gen proportional = 1 - fptp2

label variable proportional "Pure Proportional Systems"

gen proportionality = 22.69 - disprop_nomi

label variable proportionality "Proportionality, inverse of disprop_nomi"

factor proportional proportionality effparties, ml factor(1)

predict complexity

label variable complexity "Complexity of political system, factor of proportional, proportionality and effparties"

*** Control of Corruption WGI 2009

generate controlcorrup09=-0.3 if country==1 
replace controlcorrup09=-0.48 if country==2
replace controlcorrup09=-0.2 if country== 3
replace controlcorrup09=-0.87 if country==4
replace controlcorrup09=-0.73 if country==5
replace controlcorrup09=0.71 if country==6
replace controlcorrup09=-0.32 if country==7
replace controlcorrup09=-0.31 if country==8
replace controlcorrup09=-0.89 if country==9
replace controlcorrup09=-0.63 if country==10
replace controlcorrup09=-0.34 if country==11
replace controlcorrup09=-0.83 if country==12
replace controlcorrup09=1.35 if country==13
replace controlcorrup09=1.19 if country==14
replace controlcorrup09=-0.12 if country==15
replace controlcorrup09=-1.16 if country==16
replace controlcorrup09=-0.50 if country==17
replace controlcorrup09=-0.72 if country==18
replace controlcorrup09=-1.10 if country==19
replace controlcorrup09=-0.44 if country==20
replace controlcorrup09=-0.54 if country==21
replace controlcorrup09=-0.21 if country==22
replace controlcorrup09=-0.04 if country==23
replace controlcorrup09=-0.36 if country==24
label variable controlcorrup09 "Control of Corruption WGI 2009"

*** Government Effectiveness WGI 2009

generate goveffect09=0.16 if country==1 
replace goveffect09=-0.69 if country==2
replace goveffect09=-0.02 if country== 3
replace goveffect09=-0.67 if country==4
replace goveffect09=-0.95 if country==5
replace goveffect09=0.33 if country==6
replace goveffect09=0.14 if country==7
replace goveffect09=-0.23 if country==8
replace goveffect09=-0.78 if country==9
replace goveffect09=-0.59 if country==10
replace goveffect09=-0.42 if country==11
replace goveffect09=-0.92 if country==12
replace goveffect09=1.23 if country==13
replace goveffect09=0.60 if country==14
replace goveffect09=-0.10 if country==15
replace goveffect09=-0.97 if country==16
replace goveffect09=-0.33 if country==17
replace goveffect09=-0.61 if country==18
replace goveffect09=-1.51 if country==19
replace goveffect09=0.21 if country==20
replace goveffect09=-0.17 if country==21
replace goveffect09=0.30 if country==22
replace goveffect09=-0.47 if country==23
replace goveffect09=-0.05 if country==24
label variable goveffect09 "Government Effectiveness WGI 2009"


*** Political Stabiity WGI 2009

generate polstability09=-0.70 if country==1 
replace polstability09=-0.94 if country==2
replace polstability09=-0.02 if country== 3
replace polstability09=-0.33 if country==4
replace polstability09=-0.33 if country==5
replace polstability09=0.57 if country==6
replace polstability09=0.04 if country==7
replace polstability09=-1.83 if country==8
replace polstability09=-0.68 if country==9
replace polstability09=-0.53 if country==10
replace polstability09=-1.18 if country==11
replace polstability09=-0.87 if country==12
replace polstability09=0.59 if country==13
replace polstability09=0.77 if country==14
replace polstability09=0.16 if country==15
replace polstability09=-1.27 if country==16
replace polstability09=-0.24 if country==17
replace polstability09=-0.01 if country==18
replace polstability09=-1 if country==19
replace polstability09=-0.35 if country==20
replace polstability09=-0.62 if country==21
replace polstability09=-0.14 if country==22
replace polstability09=0.03 if country==23
replace polstability09=0.14 if country==24
label variable polstability09 "Political Stabiity WGI 2009"

*** Regulatory Quality WGI 2009

generate regquality09=0.23 if country==1 
replace regquality09=-0.12 if country==2
replace regquality09=0.35 if country== 3
replace regquality09=-0.26 if country==4
replace regquality09=-0.41 if country==5
replace regquality09=0.46 if country==6
replace regquality09=0.38 if country==7
replace regquality09=0.15 if country==8
replace regquality09=-1.28 if country==9
replace regquality09=-0.86 if country==10
replace regquality09=0.40 if country==11
replace regquality09=-0.42 if country==12
replace regquality09=1.48 if country==13
replace regquality09=0.37 if country==14
replace regquality09=0.11 if country==15
replace regquality09=-1.58 if country==16
replace regquality09=-0.85 if country==17
replace regquality09=-0.19 if country==18
replace regquality09=-0.92 if country==19
replace regquality09=0.28 if country==20
replace regquality09=-0.60 if country==21
replace regquality09=0.54 if country==22
replace regquality09=-0.47 if country==23
replace regquality09=-0.64 if country==24
label variable regquality09 "Regulatory Quality WGI 2009"



*** Voice and Accountabilty WGI 2009

generate voiceacc09=0.18 if country==1 
replace voiceacc09=-0.27 if country==2
replace voiceacc09=0.05 if country== 3
replace voiceacc09=-0.55 if country==4
replace voiceacc09=-0.45 if country==5
replace voiceacc09=1 if country==6
replace voiceacc09=0.58 if country==7
replace voiceacc09=-0.16 if country==8
replace voiceacc09=-0.28 if country==9
replace voiceacc09=-0.03 if country==10
replace voiceacc09=0.04 if country==11
replace voiceacc09=-0.17 if country==12
replace voiceacc09=1.01 if country==13
replace voiceacc09=1.10 if country==14
replace voiceacc09=0.49 if country==15
replace voiceacc09=-0.89 if country==16
replace voiceacc09=0.24 if country==17
replace voiceacc09=0.06 if country==18
replace voiceacc09=-0.68 if country==19
replace voiceacc09=0.55 if country==20
replace voiceacc09=0.09 if country==21
replace voiceacc09=0.53 if country==22
replace voiceacc09=0.75 if country==23
replace voiceacc09=-0.64 if country==24
label variable voiceacc09 "Voice and Accountabilty WGI 2009"


*** Rule of Law WGI 2009

generate ruleoflaw09=-0.61 if country==1 
replace ruleoflaw09=-1.07 if country==2
replace ruleoflaw09=-0.80 if country== 3
replace ruleoflaw09=-0.92 if country==4
replace ruleoflaw09=-0.79 if country==5
replace ruleoflaw09=0.53 if country==6
replace ruleoflaw09=-0.13 if country==7
replace ruleoflaw09=-0.43 if country==8
replace ruleoflaw09=-1.25 if country==9
replace ruleoflaw09=-1.14 if country==10
replace ruleoflaw09=-0.66 if country==11
replace ruleoflaw09=-0.96 if country==12
replace ruleoflaw09=1.27 if country==13
replace ruleoflaw09=0.68 if country==14
replace ruleoflaw09=-0.22 if country==15
replace ruleoflaw09=-1.59 if country==16
replace ruleoflaw09=-0.71 if country==17
replace ruleoflaw09=-0.76 if country==18
replace ruleoflaw09=-1.35 if country==19
replace ruleoflaw09=-0.48 if country==20
replace ruleoflaw09=-0.58 if country==21
replace ruleoflaw09=-0.23 if country==22
replace ruleoflaw09=-0.38 if country==23
replace ruleoflaw09=-0.17 if country==24
label variable ruleoflaw09 "Rule of Law WGI 2009"


 factor controlcorrup09 goveffect09 polstability09 regquality09 voiceacc09 ruleoflaw09, ml factor(1)

predict wgi09, reg


**** saving new dataset

save lapop10irt
